package uk.co.jonlt.AndBus;

//import java.util.ArrayList;
import java.util.ArrayList;


import org.w3c.dom.*;
import android.util.Log;

public class Buses {
	
	public ArrayList<Bus> buses;
	
	public Buses()
	{
		buses = new ArrayList<Bus>();
	}
	
	//Load the xml into an array of bus objects
	public void Load (String xml)
	{

		// XML node keys
		String KEY_ITEM  = "arrival"; // parent node
		String KEY_ROUTE = "routeName";
		String KEY_DESTINATION  = "destination";
		String KEY_TIME = "estimatedWait";
		 
		XmlParser parser = new XmlParser();
		Document doc = parser.getDomElement(xml); // getting DOM element
		 
		NodeList nl = doc.getElementsByTagName(KEY_ITEM);
		
		Log.i("Buses","About to loop through arrival nodes");
		
		//Log.i("Buses", nl.getLength());
		
		// looping through all item nodes <item>
		for (int i = 0; i < nl.getLength(); i++) 
		{
			Element e = (Element) nl.item(i);
			String route = parser.getValue(e, KEY_ROUTE);
		    String destination = parser.getValue(e, KEY_DESTINATION); // cost child value
		    String time = parser.getValue(e, KEY_TIME); // description child value
		    
		    Bus bus = new Bus(route,time,destination);
		    
		    buses.add(bus);
		}
	}
}
